<?php
class menuModel extends baseModel{

	public function sort_menu($list=array()){
		if(empty($list)){
			return;
		}
		$appid = $this->appConfig['COOKIE_PREFIX'].'admin';
		$info=$_SESSION[ $appid . '_uid' ];
		
		$user_group=api('admin_user','group_info',$info['gid']);
		$menu_purview=unserialize($user_group['menu_purview']);

		foreach ($list as $key => $value) {
			
				if(!empty($value)){
					foreach($value as $v){
						if(!in_array($v['url'], (array)$menu_purview)&&!$user_group['keep']){
							continue;
						}
				    	$data[$v['name']]=$v;
				    	$keysvalue[$v['name']] = $v['sequence'];

				}
				
			}
		}

		@asort($keysvalue);
		if(!empty($keysvalue)){
			foreach ($keysvalue as $k=>$v){
		    	$new_array[$k] = $data[$k];
		    }
	    }
		return $new_array;
	}

	public function to_html($data,$title,$top=true){
		if($top){
			$top_class='s-menu-hd';
		}else{
			$top_class='s-menu-hd2';
		}
		$html='
		<div class="m-menu-hd '.$top_class.' open"><div>'.$title.' </div></div>
			<ul class="m-menu-list s-menu-list">';
		$i=0;

		if(!empty($data)){
			foreach ($data as $name => $val) {
				$i++;
				if($i==1&&$top){
					$selected=' class="selected"';
				}else{
					$selected='';
				}
				$html.='<li><a href="javascript:;" data="'.$val['url'].'" '.$selected.' >'.$name.'</a></li>';
			}
		}
		$html.='</ul>
		<script>
		open_one();
		</script>
		';
		return $html;
	}


}